import { carrier } from "../../api";
const debug = process.env.NODE_ENV !== "production";

const MUTATION_TYPES = {
  CARRIER_LIST: "CARRIER_LIST",
  CARRIER_SIZE: "CARRIER_SIZE"
};

const state = {
  carrierList: [],
  totalCarrierSize: 0
};
const getters = {};

const mutations = {
  [MUTATION_TYPES.CARRIER_LIST](state, carrierList) {
    state.carrierList = carrierList;
  },
  [MUTATION_TYPES.CARRIER_SIZE](state, carrierSize) {
    state.totalCarrierSize = carrierSize;
  }
};

const actions = {
  async search({ commit }, filter = {}) {
    let response = await carrier.search(filter);
    if (response?.code === 0) {
      commit(MUTATION_TYPES.CARRIER_LIST, response.data?.records);
      commit(MUTATION_TYPES.CARRIER_SIZE, response.data?.total);
    }
  }
};

export default {
  strict: debug,
  namespaced: true,
  state,
  getters,
  mutations,
  actions
};
